package com.ruoyi.web.controller.video;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.video.domain.VideoCompanyTemplate;
import com.ruoyi.video.service.IVideoCompanyTemplateService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司模板关联Controller
 * 
 * @author ruoyi
 * @date 2025-06-07
 */
@Controller
@RequestMapping("/video/templateCompany")
public class VideoCompanyTemplateController extends BaseController
{
    private String prefix = "video/templateCompany";

    @Autowired
    private IVideoCompanyTemplateService videoCompanyTemplateService;

    @RequiresPermissions("video:templateCompany:view")
    @GetMapping()
    public String templateCompany()
    {
        return prefix + "/templateCompany";
    }

    /**
     * 查询公司模板关联列表
     */
    @RequiresPermissions("video:templateCompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VideoCompanyTemplate videoCompanyTemplate)
    {
        startPage();
        List<VideoCompanyTemplate> list = videoCompanyTemplateService.selectVideoCompanyTemplateList(videoCompanyTemplate);
        return getDataTable(list);
    }

    /**
     * 导出公司模板关联列表
     */
    @RequiresPermissions("video:templateCompany:export")
    @Log(title = "公司模板关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VideoCompanyTemplate videoCompanyTemplate)
    {
        List<VideoCompanyTemplate> list = videoCompanyTemplateService.selectVideoCompanyTemplateList(videoCompanyTemplate);
        ExcelUtil<VideoCompanyTemplate> util = new ExcelUtil<VideoCompanyTemplate>(VideoCompanyTemplate.class);
        return util.exportExcel(list, "公司模板关联数据");
    }

    /**
     * 新增公司模板关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司模板关联
     */
    @RequiresPermissions("video:templateCompany:add")
    @Log(title = "公司模板关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VideoCompanyTemplate videoCompanyTemplate)
    {
        return toAjax(videoCompanyTemplateService.insertVideoCompanyTemplate(videoCompanyTemplate));
    }

    /**
     * 修改公司模板关联
     */
    @RequiresPermissions("video:templateCompany:edit")
    @GetMapping("/edit/{companyId}")
    public String edit(@PathVariable("companyId") Integer companyId, ModelMap mmap)
    {
        VideoCompanyTemplate videoCompanyTemplate = videoCompanyTemplateService.selectVideoCompanyTemplateByCompanyId(companyId);
        mmap.put("videoCompanyTemplate", videoCompanyTemplate);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司模板关联
     */
    @RequiresPermissions("video:templateCompany:edit")
    @Log(title = "公司模板关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VideoCompanyTemplate videoCompanyTemplate)
    {
        return toAjax(videoCompanyTemplateService.updateVideoCompanyTemplate(videoCompanyTemplate));
    }

    /**
     * 删除公司模板关联
     */
    @RequiresPermissions("video:templateCompany:remove")
    @Log(title = "公司模板关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(videoCompanyTemplateService.deleteVideoCompanyTemplateByCompanyIds(ids));
    }
}
